// app.js
App({
  onLaunch() {
    // 初始化本地存储
    if (!wx.getStorageSync('teams')) {
      wx.setStorageSync('teams', []);
    }
    
    if (!wx.getStorageSync('groups')) {
      wx.setStorageSync('groups', []);
    }
    
    if (!wx.getStorageSync('phrases')) {
      wx.setStorageSync('phrases', []);
    }
    
    // 检查登录状态
    const userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      this.globalData.userInfo = userInfo;
    }
    
    // 获取系统信息
    wx.getSystemInfo({
      success: res => {
        this.globalData.systemInfo = res;
      }
    });
  },
  
  globalData: {
    userInfo: null,
    currentTeam: null,
    systemInfo: null
  },
  
  // 工具方法：获取当前团队
  getCurrentTeam() {
    if (!this.globalData.currentTeam) {
      const teams = wx.getStorageSync('teams') || [];
      if (teams.length > 0) {
        this.globalData.currentTeam = teams[0];
      }
    }
    return this.globalData.currentTeam;
  },
  
  // 工具方法：切换当前团队
  switchTeam(teamId) {
    const teams = wx.getStorageSync('teams') || [];
    const team = teams.find(t => t.id === teamId);
    if (team) {
      this.globalData.currentTeam = team;
      return true;
    }
    return false;
  },
  
  // 工具方法：生成唯一ID
  generateId() {
    return Date.now().toString(36) + Math.random().toString(36).substr(2, 5);
  }
});
